package com.devfest.wishmaster.model;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.annotation.SuppressLint;
import com.j256.ormlite.dao.ForeignCollection;
import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.field.ForeignCollectionField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable
public class User {

	@DatabaseField(id = true)
	private int id;

	@DatabaseField
	private String userName;

	@DatabaseField
	private String password;

	@DatabaseField
	private String name;

	@DatabaseField
	private String surname;

	@DatabaseField(dataType = DataType.DATE, canBeNull = true)
	private Date dateOfBirth;

	@ForeignCollectionField(eager = true)
	private ForeignCollection<WishList> wishList;

	@DatabaseField
	private String interests;

	@DatabaseField
	private String location;

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @return the userName
	 */
	public String getUserName() {
		return userName;
	}

	/**
	 * @param userName
	 *            the userName to set
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password
	 *            the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the surname
	 */
	public String getSurname() {
		return surname;
	}

	/**
	 * @param surname
	 *            the surname to set
	 */
	public void setSurname(String surname) {
		this.surname = surname;
	}

	/**
	 * @return the dateOfBirth
	 */
	public Date getDateOfBirth() {
		return dateOfBirth;
	}

	/**
	 * @param dateOfBirth
	 *            the dateOfBirth to set
	 */
	@SuppressLint("SimpleDateFormat")
	public void setDateOfBirth(String dateOfBirth) {
		if (dateOfBirth.equals("")) {
			this.dateOfBirth = new Date(0);
			return;
		}
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		while (!dateOfBirth.endsWith("00")) {
			dateOfBirth += "0";
		}
		try {
			this.dateOfBirth = formatter.parse(dateOfBirth.trim());
		} catch (ParseException e) {
		}
	}

	/**
	 * @return the interests
	 */
	public String getInterests() {
		return interests;
	}

	/**
	 * @param interests
	 *            the interests to set
	 */
	public void setInterests(String interests) {
		this.interests = interests;
	}

	/**
	 * @return the location
	 */
	public String getLocation() {
		return location;
	}

	/**
	 * @param location
	 *            the location to set
	 */
	public void setLocation(String location) {
		this.location = location;
	}

	/**
	 * @return the wishList
	 */
	public ForeignCollection<WishList> getWishList() {
		return wishList;
	}
	
	public User() {
	}
}